<script>
	import Vue from 'vue'
	
	export default {
		created() {
			// #ifdef APP-PLUS
			plus.navigator.closeSplashscreen(); 
			// #endif 
		},
		onLaunch: function() {
			new Promise((resolve, reject) => {
				this.$api('config', "get").then((res) => {
					this.$store.commit('config/setConfig', res.data[0])
					resolve()
				})
			}).then(() => {
				//#ifdef MP-WEIXIN
				uni.showLoading({
					title: "登陆中"
				})
				uni.login({
					provider: 'weixin'
				}).then(code => {
					code = code[1].code
					this.$api('user-center', 'loginByWeixin', {
						code,
						invitation: e.query.invitation || 0,
					}).then(res => {
						if (res.code === 0) {
							uni.hideLoading()
							// 如果使用2.7.15及以上版本建议存为uni_id_token
							uni.setStorageSync('uniIdToken', res.token)
							res.userInfo.sessionKey=res.sessionKey
							this.$store.commit('user/login', res.userInfo)
							uni.setStorageSync('uni_id_token_expired', res.tokenExpired)
							this.$isResolve()
						}
					})
			
				})
				//#endif
				//#ifndef MP-WEIXIN
				this.$isResolve() //放行app
				//#endif
			})
			//#ifdef H5
			this.$api('user-center','checkToken').then(res=>{
				if(res.code!==0){
					//处理过期
					uni.navigateTo({
						url:"/pages/login/login",
						fail:(err)=>{
						console.log(err)	
						}
					})
				}else{
					uni.reLaunch({url:"../../pages/order/examine"})
				}
			})
			//#endif
			console.log('App Launch')
			uni.getSystemInfo({
				success: function(e) {
					// #ifndef MP
					Vue.prototype.StatusBar = e.statusBarHeight;
					if (e.platform == 'android') {
						Vue.prototype.CustomBar = e.statusBarHeight + 50;
					} else {
						Vue.prototype.CustomBar = e.statusBarHeight + 45;
					};
					// #endif
		
					// #ifdef MP-WEIXIN
					Vue.prototype.StatusBar = e.statusBarHeight;
					let custom = wx.getMenuButtonBoundingClientRect();
					Vue.prototype.Custom = custom;
					Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
					// #endif		
		
					// #ifdef MP-ALIPAY
					Vue.prototype.StatusBar = e.statusBarHeight;
					Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
					// #endif
				}
			})
		},
		onShow: function() {
			console.log('App 开启')
		},
		onHide: function() {
			console.log('App 关闭')
		}
	}
</script>

<style >

	body{
		background: #FFFFFF !important;
	}
	
</style>
